2022

您所在的位置:网站首页 auto key不准 2022

2022

2023-07-17 22:38| 来源: 网络整理| 查看: 265

最近尝试clang编译c++,所以用了clangd插件代替mscpp插件,其中有不少问题,都是通过各种搜索,各种猜,才能完善,记录一下,以便广大同仁阅览。

第一步,设置clang工具链,我用msys2构建的clang64工具链,这个搜一下,非常容易构建。

第二步,下载vscode插件clangd,这是官方插件,由于与mscpp插件冲突,需要将mscpp关闭。

第三步,设置clangd插件,这是最折腾的。

设置clangd可执行文件的位置,一定要设置为你构建的clang64中的clangd可执行文件位置,切记。

因为安装插件,本身也下载一个clangd,但是那不能用,不能识别clang的标准库文件。

设置clangd参数:编译器执行程序,提示风格,是否自动加头文件,启用clang-tidy,当c++构建文件不存在时搜索位置。

"clangd.arguments": [ "--query-driver=K:\\msys64\\clang64\\bin\\clang*", "--completion-style=detailed", "--header-insertion=never", "--clang-tidy", ], "clangd.fallbackFlags": [ "-IK:\\msys64\\mingw64\\include\\" ],

设置编辑器格式化风格。这个需要在项目文件夹下建立一个 “ .clang-format ” 文件,内容如下:我使用的时微软风格,没办法,习惯mscpp的format了。

--- Language: Cpp # BasedOnStyle: Microsoft AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignArrayOfStructures: None AlignConsecutiveMacros: None AlignConsecutiveAssignments: None AlignConsecutiveBitFields: None AlignConsecutiveDeclarations: None AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortEnumsOnASingleLine: false AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: None AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: Never AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: MultiLine AttributeMacros: - __capability BinPackArguments: true BinPackParameters: true BraceWrapping: AfterCaseLabel: false AfterClass: true AfterControlStatement: Always AfterEnum: true AfterFunction: true AfterNamespace: true AfterObjCDeclaration: true AfterStruct: true AfterUnion: false AfterExternBlock: true BeforeCatch: true BeforeElse: true BeforeLambdaBody: false BeforeWhile: false IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: true BreakBeforeBraces: Custom BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DeriveLineEnding: true DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve IncludeCategories: - Regex: '^"(llvm|llvm-c|clang|clang-c)/' Priority: 2 SortPriority: 0 CaseSensitive: false - Regex: '^(


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3